package com.example.trans;

import com.example.Employee;
import com.example.PaymentClassification;
import com.example.PayrollDatabase;
import com.example.Transaction;
import com.example.classification.CommissionedClassification;
import com.example.classification.SalesReceipt;
import com.exception.NoSuchEmployeeException;
import com.exception.NotCommissionedClassificationException;


public class SalesReceiptTransaction implements Transaction {
    private  int empId;
    private final  String date;
    private double amount;

    public SalesReceiptTransaction(int empId, String date, double amount) {
        this.empId = empId;
        this.date = date;
        this.amount = amount;
    }

    @Override
    public void execute() {
        Employee e  = PayrollDatabase.getEmployee(empId);
        if (e == null)
            throw  new NoSuchEmployeeException();
        PaymentClassification pc = e.getPaymentClassification();
        if (pc instanceof  CommissionedClassification) {
        CommissionedClassification cc = (CommissionedClassification) pc;
        SalesReceipt sr =  new SalesReceipt(date,amount);
        cc.addSalesReceipt(sr);
        } else {
            throw new NotCommissionedClassificationException();
        }
        
    }

}
